package com.huike.clues.service.impl;


import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.mapper.TbClueMapper;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.utils.SecurityUtils;
import com.huike.common.utils.bean.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 线索跟进记录Service业务层处理
 *
 * @date 2022-04-22
 */
@Service
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {
    @Autowired
    private TbClueTrackRecordMapper clueTrackRecordMapper;

    @Autowired

    private TbClueMapper tbClueMapper;

    @Override
    public Integer addClueTrackRecord(ClueTrackRecordVo tbClueTrackRecordvo) {
        SecurityUtils.getUsername();
        final TbClue tbClue = new TbClue();
        final TbClueTrackRecord tbClueTrackRecord = new TbClueTrackRecord();
        BeanUtils.copyBeanProp(tbClue,tbClueTrackRecordvo);
        //设置原有的tbclue的Id，如果不设置就会报错
        tbClue.setId(tbClueTrackRecordvo.getClueId());
        //同时要更改状态
        tbClue.setStatus("2");
        BeanUtils.copyBeanProp(tbClueTrackRecord,tbClueTrackRecordvo);
        //到这边的都是跟进中的，所以类型状态默认是0
        tbClueTrackRecord.setType("0");

        //tbClueTrackRecord.setCreateBy(tbClue.getCreateBy());
        Integer i = clueTrackRecordMapper.addClueTrackRecord(tbClueTrackRecord);
        tbClueMapper.updateTbClue(tbClue);
        return i;
    }

    @Override
    public List<ClueTrackRecordVo> selectByClueId(Long clueId) {
        List<ClueTrackRecordVo> list =clueTrackRecordMapper.selectByClueId(clueId);

        return list;
    }
}
